package com.lenin.omena.server;

import javax.jdo.Transaction;

import com.lenin.omena.shared.domain.Produce;
import com.lenin.omena.shared.domain.User;

//@Repository("produceDAO")
public class ProduceDAO extends JdoDAO<Long, Produce> {

	public ProduceDAO() {
		super();
	}
	
	
	public Produce saveProduce(Produce produce, Produce detachedProduce) {
		
		
		Transaction tx = pm.currentTransaction();

		Produce entity = null;
		
		try
		{
		    tx.begin(); // Start the PM transaction

		    produce.setName(detachedProduce.getName());
		    produce.setAmount(detachedProduce.getAmount());
		    produce.setPrice(detachedProduce.getPrice());
		    entity = pm.makePersistent(produce);

		    tx.commit(); // Commit the PM transaction
		}
		finally
		{
		    if (tx.isActive())
		    {
		        tx.rollback(); // Error occurred so rollback the PM transaction
		    }
		}
		
		return entity;
		
		
	}
	
	
}
